﻿using System;

namespace FactoryPattern.AbstractFactory;

public static class AbstractFactory
{
    public abstract class Product
    {
        public abstract void DisplayProductName();
    }

    public abstract class ProductPad : Product;

    public class HuaweiPad : ProductPad
    {
        public override void DisplayProductName()
        {
            Console.WriteLine("华为平板");
        }
    }

    public class ApplePad : ProductPad
    {
        public override void DisplayProductName()
        {
            Console.WriteLine("苹果平板");
        }
    }

    public abstract class ProductSmartphone : Product;

    public class HuaweiSmartphone : ProductSmartphone
    {
        public override void DisplayProductName()
        {
            Console.WriteLine("华为手机");
        }
    }

    public class AppleSmartphone : ProductSmartphone
    {
        public override void DisplayProductName()
        {
            Console.WriteLine("苹果手机");
        }
    }

    public abstract class Factory
    {
        public abstract ProductPad CreatePad();
        public abstract ProductSmartphone CreateSmartphone();
    }

    public class HuaweiFactory : Factory
    {
        public override ProductPad CreatePad() => new HuaweiPad();
        public override ProductSmartphone CreateSmartphone() => new HuaweiSmartphone();
    }

    public class AppleFactory : Factory
    {
        public override ProductPad CreatePad() => new ApplePad();

        public override ProductSmartphone CreateSmartphone() => new AppleSmartphone();
    }


    public static void TestAbstractFactory()
    {
        var huaweiFactory = new HuaweiFactory();
        huaweiFactory.CreatePad().DisplayProductName();
        huaweiFactory.CreateSmartphone().DisplayProductName();

        var appleFactory = new AppleFactory();
        appleFactory.CreatePad().DisplayProductName();
        appleFactory.CreateSmartphone().DisplayProductName();
    }
}